package com.gxa.web_admin.controller.accesscontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.Role;
import com.gxa.modules.pojo.RoleType;
import com.gxa.modules.pojo.User;
import com.gxa.modules.service.accessservice.UserService;
import com.gxa.modules.service.accessservice.impl.UserServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.ArrayList;

@RestController
@RequestMapping(value = "user")
@Api(value = "用户管理模块",tags = "用户管理API")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询所有角色信息
     * @return 返回所有角色信息
     */
    @RequestMapping(value = "selectUser",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有用户信息接口",notes = "根据传入信息查询用户信息",httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userName",value = "用户名称",paramType = "query",dataType = "String"),
        @ApiImplicitParam(name = "page",value = "当前页码",paramType = "query",dataType = "String",required = true),
        @ApiImplicitParam(name = "size",value = "每页显示条数",paramType = "query",dataType = "String",required = true)
    })

    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectUser(String userName,String page,String size){
        return userService.selectUser(userName,page,size);
    }


    /**
     * 新增用户
     * @return 返回成功
     */
    @RequestMapping(value = "insertUser",method = RequestMethod.POST)
    @ApiOperation(value = "新增用户接口",notes = "新增用户",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertUser(@RequestBody @ApiParam(name = "insertUserJson",
            value = "用户名称、联系方式、性别、身份证号、邮箱、登录名称、密码、创建时间",required = true)
                                User user ){
        return userService.insertUser(user);
    }


    /**
     * 删除用户
     * @return 返回删除成功
     */
    @RequestMapping(value = "deleteUser",method = RequestMethod.POST)
    @ApiOperation(value = "删除用户接口",notes = "根据传入id删除用户",httpMethod = "POST", response = String.class)
    @ApiImplicitParam(name = "userId",value = "用户id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteUser(String userId){
        return userService.deleteUser(userId);
    }

    /**
     * 修改用户
     * @return 返回成功
     */
    @RequestMapping(value = "updateUser",method = RequestMethod.POST)
    @ApiOperation(value = "修改用户接口",notes = "修改用户",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateUser(@RequestBody @ApiParam(name = "updateUserJson",
            value = "用户名称、联系方式、性别、身份证号、邮箱、登录名称、密码、角色id、修改时间",required = true)
                                User user){

        return userService.updateUser(user);
    }
}
